<?php if(!defined('CALL')) exit('No direct script access allowed');

include_once('lib/xtemplate.class.php');

class vUsercard
{
	function generate($selected, $actor, $to_users = TRUE)
	{
		$male = (bool) ($selected->props['male'] == "Y");
		$gender1 = $male ? "он"  : "она";
		$gender2 = $male ? "ним" : "ней";
		$gender3 = $male ? "его" : "её";
		
		$cardX = new XTemplate('xtpl/usercard.xtpl');
		$cardX->assign('postype', 'static');
		$cardX->assign('card_id', 'maincard');
		$cardX->assign('root', ROOT_URL);
		$cardX->assign('avatar', $selected->props['face']);
		$cardX->assign('user_id', $selected->id);
		$cardX->assign('username', $selected->props['username']);
		$cardX->assign('note', $selected->props['note']);
		$cardX->assign('city', $selected->props['city']);
		
		$cardX->assign('gender1', $gender1);
		$cardX->assign('gender2', $gender2);
		$cardX->assign('gender3', $gender3);
		
		$cardX->assign('fut', (int)$selected->stat["FUT"]);
		$cardX->assign('fut_sfx', Utils::select_str($selected->stat["FUT"], 'е', 'я', 'й'));
		
		$cardX->assign('sha', (int)$selected->stat["SHA"]);
		$cardX->assign('sha_sfx', Utils::select_str($selected->stat["SHA"], 'и', 'ях', 'ях'));
		
		$cardX->assign('pop', (int)$selected->stat["POP"]);
		$cardX->assign('pop_sfx', Utils::select_str($selected->stat["POP"], 'а', 'а', ''));
		
		$num = count($selected->links['WM']);
		$cardX->assign('uid', $selected->id);
		$cardX->assign('watched', $num);
		$cardX->assign('sfx_31', Utils::select_str($num, 'ет', 'ют', 'ют'));
		$cardX->assign('watched_sfx', Utils::select_str($num, '', 'а', ''));
		
		$num = count($selected->links['WS']);
		$cardX->assign('watching', $num);
		$cardX->assign('sfx_41', Utils::select_str($num, 'ит', 'ят', 'ят'));
		$cardX->assign('watching_sfx', Utils::select_str($num, '', 'а', ''));
		
		$cardX->parse('root');
		return $cardX->text('root');
	}
}